/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * alamcen2.java
 *
 * Created on 19/11/2011, 07:44:36 PM
 */

package GUIalmacen;

import BE.BENodo;
import BE.BEPallet;
import BE.BEPosicion;
import BE.BEPosicionxRack;
import BE.BERack;
import BE.BERackxNodo;
import BL.BLAlmacen;
import BL.BLCardex;
import BL.BLGrafoAlmacen;
import BL.BLPallet;
import BL.BLPosicionxrack;
import BL.BLRack;

import GUI.Racks.GUIMantenimientoRack;
import java.awt.Color;
import java.awt.Font;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.JTextField;

/**
 *
 * @author Cristian
 */
public class almacen2 extends javax.swing.JFrame {

    /** Creates new form alamcen2 */
int cod;

int i;
int j;

private List<MiBotonRack> lstbotones = new ArrayList<MiBotonRack>();
private List<MiBotonRack> lstrack = new ArrayList<MiBotonRack>();

private List<BEPallet> lstpallet= new ArrayList<BEPallet>();
private List<BEPosicionxRack> lstposiciones= new ArrayList<BEPosicionxRack>();


    private int [][] matriz={
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,1,1,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},

    }
    ;

     private int [][] rack={
         {1,1,0,0,0,0,0,0,0,0},
         {0,0,1,1,0,0,0,0,0,0},
         {0,0,0,0,0,0,0,0,0,0},
         {0,0,0,0,0,0,0,0,0,0}
     }
     ;


     private MiBotonRack [][] botones = new MiBotonRack[30][30] ;
    private  int ancho;
    private  int largo;
    private BLGrafoAlmacen blGrafoAlmacen;


    private List<BERackxNodo> getLstRackxNodo = new ArrayList<BERackxNodo>();
 List<BENodo> grafo = new ArrayList<BENodo>();

 
 
    public almacen2() throws IOException  {
        initComponents();
        //setSize(822,654);
        
        
    //    panel.setLocation(30, 30);
        inicializar();
            this.setVisible(true);
 //           System.out.println(panel.getLocation().x +"   "+panel.getLocation().y);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        panel = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        jButton2 = new javax.swing.JButton();
        jLabel7 = new javax.swing.JLabel();
        jButton3 = new javax.swing.JButton();
        jLabel8 = new javax.swing.JLabel();
        jButton4 = new javax.swing.JButton();
        jLabel14 = new javax.swing.JLabel();
        jButton6 = new javax.swing.JButton();
        jLabel15 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        txtCodPallet = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        txtProducto = new javax.swing.JTextField();
        txtFilaPallet = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        txtColumnaPallet = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        txtCantidad = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        txtFecha = new javax.swing.JTextField();
        pnlRack = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        txtCodRack = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        txtZona = new javax.swing.JTextField();
        txtFilaRack = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        txtColumanRack = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        btnCancelar = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtRuta = new javax.swing.JTextArea();
        btnCancelar1 = new javax.swing.JButton();

        setMinimumSize(new java.awt.Dimension(822, 660));
        setResizable(false);

        panel.setBackground(new java.awt.Color(0, 153, 153));
        panel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        panel.setMaximumSize(new java.awt.Dimension(600, 600));
        panel.setMinimumSize(new java.awt.Dimension(600, 600));
        panel.setPreferredSize(new java.awt.Dimension(600, 600));

        javax.swing.GroupLayout panelLayout = new javax.swing.GroupLayout(panel);
        panel.setLayout(panelLayout);
        panelLayout.setHorizontalGroup(
            panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 598, Short.MAX_VALUE)
        );
        panelLayout.setVerticalGroup(
            panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 598, Short.MAX_VALUE)
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Leyenda", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 10))); // NOI18N
        jPanel2.setFont(new java.awt.Font("Tahoma", 0, 10));
        jPanel2.setMaximumSize(new java.awt.Dimension(206, 50));
        jPanel2.setMinimumSize(new java.awt.Dimension(206, 50));
        jPanel2.setPreferredSize(new java.awt.Dimension(206, 50));
        jPanel2.setRequestFocusEnabled(false);

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUIalmacen/camino.png"))); // NOI18N

        jLabel6.setText("Rack");

        jLabel7.setText("Vacio");

        jButton3.setIcon(new javax.swing.ImageIcon("/usr/home/a20070524/yo/src/GUIalmacen/caja2.png")); // NOI18N

        jLabel8.setText("Pallet Ocupado");

        jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUIalmacen/obstaculo.png"))); // NOI18N

        jLabel14.setText("Pallet Anulado");

        jButton6.setBackground(new java.awt.Color(255, 255, 0));

        jLabel15.setText("Origen");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel6))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel8))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel7))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jButton6, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel15))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel14)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel14))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton6, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel15)))
        );

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Pallet", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 10))); // NOI18N
        jPanel1.setMaximumSize(new java.awt.Dimension(200, 200));
        jPanel1.setMinimumSize(new java.awt.Dimension(200, 200));
        jPanel1.setPreferredSize(new java.awt.Dimension(200, 200));

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 10));
        jLabel1.setText("Código:");

        txtCodPallet.setFont(new java.awt.Font("Tahoma", 0, 10));
        txtCodPallet.setDisabledTextColor(new java.awt.Color(0, 0, 0));
        txtCodPallet.setEnabled(false);

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 10));
        jLabel2.setText("Producto:");

        txtProducto.setFont(new java.awt.Font("Tahoma", 0, 10));
        txtProducto.setDisabledTextColor(new java.awt.Color(0, 0, 0));
        txtProducto.setEnabled(false);

        txtFilaPallet.setFont(new java.awt.Font("Tahoma", 0, 10));
        txtFilaPallet.setDisabledTextColor(new java.awt.Color(0, 0, 0));
        txtFilaPallet.setEnabled(false);

        jLabel4.setFont(new java.awt.Font("Tahoma", 0, 10));
        jLabel4.setText("Fila:");

        txtColumnaPallet.setFont(new java.awt.Font("Tahoma", 0, 10));
        txtColumnaPallet.setDisabledTextColor(new java.awt.Color(0, 0, 0));
        txtColumnaPallet.setEnabled(false);

        jLabel5.setFont(new java.awt.Font("Tahoma", 0, 10));
        jLabel5.setText("Columna:");

        jLabel12.setFont(new java.awt.Font("Tahoma", 0, 10));
        jLabel12.setText("Cantidad:");

        txtCantidad.setFont(new java.awt.Font("Tahoma", 0, 10));
        txtCantidad.setDisabledTextColor(new java.awt.Color(0, 0, 0));
        txtCantidad.setEnabled(false);

        jLabel13.setFont(new java.awt.Font("Tahoma", 0, 10));
        jLabel13.setText("F Vencimiento:");

        txtFecha.setFont(new java.awt.Font("Tahoma", 0, 10));
        txtFecha.setDisabledTextColor(new java.awt.Color(0, 0, 0));
        txtFecha.setEnabled(false);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel12)
                            .addComponent(jLabel5)
                            .addComponent(jLabel4)
                            .addComponent(jLabel2))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 35, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(txtCantidad, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(txtColumnaPallet, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(txtFilaPallet, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(txtProducto, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE))))
                            .addComponent(txtCodPallet, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(jLabel13)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(txtFecha, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(16, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(txtCodPallet, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtProducto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtFilaPallet, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtColumnaPallet, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5)))
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtCantidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel12))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel13)
                    .addComponent(txtFecha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pnlRack.setBackground(new java.awt.Color(255, 255, 255));
        pnlRack.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        pnlRack.setMaximumSize(new java.awt.Dimension(200, 200));
        pnlRack.setMinimumSize(new java.awt.Dimension(200, 200));
        pnlRack.setPreferredSize(new java.awt.Dimension(200, 200));

        javax.swing.GroupLayout pnlRackLayout = new javax.swing.GroupLayout(pnlRack);
        pnlRack.setLayout(pnlRackLayout);
        pnlRackLayout.setHorizontalGroup(
            pnlRackLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 198, Short.MAX_VALUE)
        );
        pnlRackLayout.setVerticalGroup(
            pnlRackLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 198, Short.MAX_VALUE)
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Rack", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 10))); // NOI18N
        jPanel3.setMaximumSize(new java.awt.Dimension(200, 200));
        jPanel3.setMinimumSize(new java.awt.Dimension(200, 200));

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 10));
        jLabel3.setText("Código:");

        txtCodRack.setFont(new java.awt.Font("Tahoma", 0, 10));
        txtCodRack.setDisabledTextColor(new java.awt.Color(0, 0, 0));
        txtCodRack.setEnabled(false);

        jLabel9.setFont(new java.awt.Font("Tahoma", 0, 10));
        jLabel9.setText("Zona");

        txtZona.setFont(new java.awt.Font("Tahoma", 0, 10));
        txtZona.setDisabledTextColor(new java.awt.Color(0, 0, 0));
        txtZona.setEnabled(false);

        txtFilaRack.setFont(new java.awt.Font("Tahoma", 0, 10));
        txtFilaRack.setDisabledTextColor(new java.awt.Color(0, 0, 0));
        txtFilaRack.setEnabled(false);

        jLabel10.setFont(new java.awt.Font("Tahoma", 0, 10));
        jLabel10.setText("Fila:");

        txtColumanRack.setFont(new java.awt.Font("Tahoma", 0, 10));
        txtColumanRack.setDisabledTextColor(new java.awt.Color(0, 0, 0));
        txtColumanRack.setEnabled(false);

        jLabel11.setFont(new java.awt.Font("Tahoma", 0, 10));
        jLabel11.setText("Columna:");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel10)
                    .addComponent(jLabel11)
                    .addComponent(jLabel3)
                    .addComponent(jLabel9))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtCodRack, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtColumanRack, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtFilaRack, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtZona, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txtCodRack, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(txtZona, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(txtFilaRack, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(txtColumanRack, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(57, Short.MAX_VALUE))
        );

        btnCancelar.setText("Salir");
        btnCancelar.setMaximumSize(new java.awt.Dimension(100, 25));
        btnCancelar.setMinimumSize(new java.awt.Dimension(100, 25));
        btnCancelar.setPreferredSize(new java.awt.Dimension(100, 25));
        btnCancelar.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseMoved(java.awt.event.MouseEvent evt) {
                btnCancelarMouseMoved(evt);
            }
        });
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });

        txtRuta.setColumns(20);
        txtRuta.setEditable(false);
        txtRuta.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        txtRuta.setRows(5);
        txtRuta.setBorder(javax.swing.BorderFactory.createTitledBorder("Ruta"));
        txtRuta.setDisabledTextColor(new java.awt.Color(0, 0, 0));
        jScrollPane1.setViewportView(txtRuta);

        btnCancelar1.setText("Actualizar");
        btnCancelar1.setMaximumSize(new java.awt.Dimension(100, 25));
        btnCancelar1.setMinimumSize(new java.awt.Dimension(100, 25));
        btnCancelar1.setPreferredSize(new java.awt.Dimension(100, 25));
        btnCancelar1.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseMoved(java.awt.event.MouseEvent evt) {
                btnCancelar1MouseMoved(evt);
            }
        });
        btnCancelar1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelar1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(800, 800, 800)
                        .addComponent(btnCancelar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btnCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(30, 30, 30)
                        .addComponent(panel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(7, 7, 7)
                                .addComponent(pnlRack, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(40, 40, 40))
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                    .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, 189, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(28, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jPanel3, 0, 192, Short.MAX_VALUE)
                                .addGap(19, 19, 19))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 192, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 206, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(pnlRack, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(16, 16, 16))
                    .addComponent(panel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnCancelar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(19, 19, 19))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    
    public void inicializar() throws IOException{
        BLAlmacen blAlmacen = new BLAlmacen();
        ancho=blAlmacen.getAncho();
        largo=blAlmacen.getLargo();
        blGrafoAlmacen = new BLGrafoAlmacen (ancho,largo);
        blGrafoAlmacen.cargarRacks();
       getLstRackxNodo=blGrafoAlmacen.getLstRackxNodo();
   
       
       BLPallet bLPallet= new BLPallet();
       lstpallet=bLPallet.buscarPalletUbicados();
       
       BLPosicionxrack bLPosicionxrack = new BLPosicionxrack();
       lstposiciones= bLPosicionxrack.getTodos();

grafo = blGrafoAlmacen.getBeGrafoAlmacen().getGrafo();
      cargarAlmacen();
     
            dibujaalmacen();

           JTextField texto= new JTextField();
                   for (int i=0; i<ancho; i++)  {  
                       texto= new JTextField();
                       texto.setFont(new Font ("Arial", 1, 10));
                   texto.setSize(18, 18);
                   texto.setText((i+1)+"");
                   texto.setEditable(false);
                   texto.setLocation(30+(i*20), 10);
                   this.add(texto);
                   
                   
                   }
                   
                   
                   
                   for (int i=0; i<largo; i++)  {  
                       texto= new JTextField();
                       texto.setFont(new Font ("Arial", 1, 10));
                   texto.setSize(18, 18);
                   texto.setText((i+1)+"");
                   texto.setEditable(false);
                   texto.setLocation(10,30+(i*20));
                   this.add(texto);
                   
                   
                   }
                   
                   
    }
    
    
    private void btnCancelarMouseMoved(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnCancelarMouseMoved
       
    }//GEN-LAST:event_btnCancelarMouseMoved

    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
        dispose();
    }//GEN-LAST:event_btnCancelarActionPerformed

private void btnCancelar1MouseMoved(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnCancelar1MouseMoved
// TODO add your handling code here:
}//GEN-LAST:event_btnCancelar1MouseMoved

private void btnCancelar1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelar1ActionPerformed
        try {
            cargarAlmacen();
             dibujaalmacen();
             panel.repaint();
        } catch (IOException ex) {
            Logger.getLogger(almacen2.class.getName()).log(Level.SEVERE, null, ex);
        }
     
           

    // TODO add your handling code here:
}//GEN-LAST:event_btnCancelar1ActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                try {
                    new almacen2().setVisible(true);
                } catch (IOException ex) {
                    Logger.getLogger(almacen2.class.getName()).log(Level.SEVERE, null, ex);
                }
               
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnCancelar1;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton6;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPanel panel;
    private javax.swing.JPanel pnlRack;
    private javax.swing.JTextField txtCantidad;
    private javax.swing.JTextField txtCodPallet;
    private javax.swing.JTextField txtCodRack;
    private javax.swing.JTextField txtColumanRack;
    private javax.swing.JTextField txtColumnaPallet;
    private javax.swing.JTextField txtFecha;
    private javax.swing.JTextField txtFilaPallet;
    private javax.swing.JTextField txtFilaRack;
    private javax.swing.JTextField txtProducto;
    private javax.swing.JTextArea txtRuta;
    private javax.swing.JTextField txtZona;
    // End of variables declaration//GEN-END:variables

    
    
    
    
    
    public void dibujaruta(List<BENodo> lstruta,List<BENodo> lstpallet) throws IOException{
        BufferedImage imagen1 =ImageIO.read(new File("./ruta.png"));
        BufferedImage imagen2 =ImageIO.read(new File("./obstaculo.png"));
        Icon icon1 = new ImageIcon(imagen1);
        Icon icon2 = new ImageIcon(imagen2);
        
        
        for (int k = 0; k < lstpallet.size(); k++) {
            BENodo bENodo = lstpallet.get(k);
            for (int l = 0; l < lstbotones.size(); l++) {
                MiBotonRack btnRack = lstbotones.get(l);
                if(btnRack.getObjnodo().getIdNodo()==bENodo.getIdNodo())
                    lstbotones.get(l).setIcon(icon2);
                
            }
            
        }
        
        
        
        for (int k = 0; k < lstruta.size(); k++) {
            BENodo bENodo = lstruta.get(k);
            for (int l = 0; l < lstbotones.size(); l++) {
                MiBotonRack btnRack = lstbotones.get(l);
                if(btnRack.getObjnodo().getIdNodo()==bENodo.getIdNodo()){
                    lstbotones.get(l).setIcon(null);
                lstbotones.get(l).setBackground(Color.RED);
                lstbotones.get(l).setEnabled(true);
                }
            }
            
        }
        
        panel.removeAll();
        dibujaalmacen();
    }
    
    
    
    private void dibujalmacenAntiguo() throws IOException {

        //this.setSize(822,654);
        BufferedImage imagen1 =ImageIO.read(new File("pallet.png"));

        BufferedImage imagen2 =ImageIO.read(new File("camino.png"));
        Icon icon1 = new ImageIcon(imagen1);
                Icon icon2 = new ImageIcon(imagen2);

//                JPanel panel=new JPanel();
;
        for (i=0;i<matriz.length;i++)
            for ( j=0;j<matriz[i].length;j++){
                JButton boton = new JButton("");

                boton.setHorizontalTextPosition(0);

                boton.setVerticalTextPosition(0);
                boton.setSize(20, 20);

                if (matriz[i][j]==0)
                {   // boton.setIcon(icon1);
                    boton.setEnabled(false);}

                else
                {
                    boton.setIcon(icon1);
                 boton.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e)
            {
                    
                            //Execute when button is pressed
                            //dibujrack();
                            txtFilaRack.setText(i+"");
                            txtCantidad.setText(j+"");
                      
            }
        });


                }
                    boton.setLocation(j*20, i*20);
//                    boton.setVisible(true);
                    panel.add(boton);
//            }   panel.setSize(900,900);
//                panel.setLocation(0, 0);
//                panel.setVisible(true);
//                this.add(panel);

    }
}


      private void dibujrack(List<BEPallet> listapallet,BERack objrack) throws IOException {

        pnlRack.removeAll();

        BufferedImage imagen =ImageIO.read(new File("./caja.png"));
        
        Icon icon1 = new ImageIcon(imagen);
        
        
        BufferedImage imagen2 =ImageIO.read(new File("./caja2.png"));
        
        Icon icon2 = new ImageIcon(imagen2);

                 BLPosicionxrack blpxr = new BLPosicionxrack();
        List <BEPosicionxRack> lista =new ArrayList<BEPosicionxRack>();

        lista=blpxr.posicionebyRack(objrack.getIdRack());


        int x;
        int y;

          for (int i = 0; i < lista.size(); i++) {
              BEPosicionxRack bEPosicionxRack = lista.get(i);

                BEPallet objpallet=new BEPallet();
                BLPallet bLPallet= new BLPallet();

                MiBotonPallet boton= new MiBotonPallet();

                if (bEPosicionxRack.getEstado()==1)
                {       
                    objpallet = buscapallet(bEPosicionxRack.getIdposicionxrack(),listapallet);
                     boton = new MiBotonPallet(bEPosicionxRack,objpallet);
                    boton.setIcon(icon2);
                     boton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                        try {
                            btnPallet(evt);
                        } catch (IOException ex) {
                            Logger.getLogger(almacen2.class.getName()).log(Level.SEVERE, null, ex);
                        }
                   
            }
        });
              }
                else 

                {
                    boton = new MiBotonPallet(bEPosicionxRack, null);
 boton.setEnabled(false);
  if (bEPosicionxRack.getEstado()==2)
      boton.setIcon(icon1);
 
 
              }
                boton.setSize(20, 20);

                x=bEPosicionxRack.getFila();
                y=bEPosicionxRack.getColumna();

              
                    boton.setLocation((y-1)*20,pnlRack.getHeight()- ((x)*20));
                   boton.setVisible(true);
                    pnlRack.add(boton);
//
          }

     
       
        
        pnlRack.repaint();
}








    private void cargarAlmacen() throws IOException {

        BERack objrack= new BERack();
        BufferedImage imagen1 =ImageIO.read(new File("./pallet.png"));
        BufferedImage imagen2 =ImageIO.read(new File("./camino.png"));
        Icon icon1 = new ImageIcon(imagen1);
                Icon icon2 = new ImageIcon(imagen2);


     
         MiBotonRack objboton = new MiBotonRack();


         List<Integer> nodosAnulados = blGrafoAlmacen.getBeGrafoAlmacen().getAnulados();
        int size = blGrafoAlmacen.getBeGrafoAlmacen().size();
        List<BENodo> grafo = blGrafoAlmacen.getBeGrafoAlmacen().getGrafo();

        int id,x,y;

        BLRack blrack  = new BLRack();
        blrack.cargar();
        for (int i = 0; i < grafo.size(); i++) {
            BENodo objNodo = grafo.get(i);
            id=objNodo.getIdNodo();
            x=objNodo.getX();
            y=objNodo.getY();
            if(nodosAnulados.contains(id))
            {
               objrack=blrack.getRackfromLst(objNodo.getIdrack());
                objboton = new MiBotonRack(objNodo,  objrack);
                
              List<BEPallet> aux= new ArrayList<BEPallet>(); 
                
                aux=cargarpallet(objrack.getIdRack());
                objboton.setLstpallet(aux);

                objboton.setIcon(icon2);
                objboton.setSize(20, 20);

                x=objNodo.getX()-1;
                y=objNodo.getY()-1;
                objboton.setLocation(x*20, y*20);
                
                
objboton.setText(objrack.getIdRack()+"");

                objboton.setToolTipText("Fila: "+objNodo.getX()+" Columna:"+objNodo.getY());
                lstbotones.add(objboton);

                lstrack.add(objboton);}


           else{


                objboton = new MiBotonRack(objNodo, null);

                objboton.setIcon(icon1);
                objboton.setEnabled(false);
                objboton.setSize(20, 20);

                x=objNodo.getX()-1;
                y=objNodo.getY()-1;
                
                if (x==0 && y==0)
                { objboton.setBackground(Color.YELLOW);
                objboton.setEnabled(true);
                objboton.setIcon(null);
                }   
                objboton.setLocation(x*20, y*20);
              
                objboton.setToolTipText("Fila: "+objNodo.getY()+" Columna:"+objNodo.getX());
                lstbotones.add(objboton);


        }

         }

//        
//        for (int i = 0; i < nodosAlmacen.size(); i++) {
//            BENodo bENodo = nodosAlmacen.get(i);
//
//
//            if(existeEnLista(bENodo, objrack))
//                 objboton = new MiBotonRack(bENodo,nodoactual.getBeRack()) ;
//
//
//             objboton.setSize(20, 20);
//
//                x=bENodo.getX()-1;
//            y=bENodo.getY()-1;
//                objboton.setLocation(x*20, y*20);
//                lstbotones.add(objboton);
//
//        }


        for (int i = 0; i < lstrack.size(); i++) {

            
           lstrack.get(i).addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                    try {
                        btnRack(evt);
                    } catch (IOException ex) {
                        Logger.getLogger(almacen2.class.getName()).log(Level.SEVERE, null, ex);
                    }
                   
            }
        });

        }


    }


    public void setTextRuta (String ruta){
        txtRuta.setText(ruta);
    }


      public void btnRack(ActionEvent e) throws IOException
            {
          MiBotonRack aux =new MiBotonRack(null, null);
          aux=(MiBotonRack)(e.getSource());
         //System.out.println("//////////   "  +aux.getObjRack().getIdRack());


                            txtCodRack.setText(aux.getObjRack().getNombre());
                            txtColumanRack.setText(aux.getObjnodo().getX()+"");

                          //  System.out.println(aux.getObjRack().getIdRack());

                            txtFilaRack.setText(aux.getObjnodo().getY()+"");
                            txtZona.setText(aux.getObjRack().getIdzona()+"");
                           
                            
                            if (aux.getLstpallet()!=null)
                            dibujrack(aux.getLstpallet(),aux.getObjRack());







            }


public void btnPallet(ActionEvent e) throws IOException
            {
          MiBotonPallet aux =new MiBotonPallet(null, null);
          aux=(MiBotonPallet)(e.getSource());
         

                            txtCodPallet.setText(aux.getObjPallet().getIdPallet()+"");
                            txtColumnaPallet.setText(aux.getPosicion().getColumna()+"");
                            txtProducto.setText(aux.getObjPallet().getProducto().getNombre());
                            txtFilaPallet.setText(aux.getPosicion().getFila()+"");
                            txtCantidad.setText(aux.getObjPallet().getCantidad()+"");
                            txtFecha.setText(aux.getObjPallet().getFechaVencimiento().toString());
                            

            }


    private void dibujaalmacen() throws IOException {
                
        for (int i = 0; i < lstbotones.size(); i++) {
             panel.add(lstbotones.get(i));
            
        }

    }

    private boolean existeEnlista(List<BEPallet> listapallet,int idposicion ) {
        boolean resp=false;




        for (int i = 0; i < listapallet.size(); i++) {
            


            if (listapallet.get(i).getPosicionxrack().getIdposicionxrack()==idposicion)
            {resp=true;
            break;}
        }

               return resp;


    }

    private BERack buscaNodo(BENodo bENodo,int idnodo ) {

       BERack objrack=null;

        for (int i = 0; i < getLstRackxNodo.size(); i++) {
           BERackxNodo objnodo=new BERackxNodo();
           objnodo= getLstRackxNodo.get(i);




           for (int j = 0; i < objnodo.getLstNodo().size(); i++)
           if (objnodo.getLstNodo().get(j).getIdNodo()==idnodo){
               
              objrack=objnodo.getBeRack();
                return objrack;
              
           }

        }

       return objrack;
    }

    private BEPallet buscapallet(int idpos, List<BEPallet> listapallet) {
        for (int k = 0; k < listapallet.size(); k++) {
            BEPallet bEPallet = listapallet.get(k);
            
            if(bEPallet.getPosicionxrack().getIdposicionxrack()==idpos)
                return bEPallet;
            
        }
        return null;
    }

    private List<BEPallet> cargarpallet(int idRack) {
        List<BEPallet> lista = new ArrayList<BEPallet>();
        
        
        for (int i=0;i<lstposiciones.size();i++){
            
            BEPosicionxRack pos=lstposiciones.get(i);
            if(pos.getIdrack()==idRack){
                
                for (int j=0;j<lstpallet.size();j++){
                    
                    if(lstpallet.get(j).getPosicionxrack().getIdposicionxrack()==pos.getIdposicionxrack())
                        lista.add(lstpallet.get(j));
                }
                
                
                
            }
            
        }
        
        
        
        return lista;
    }

    
}
